<?php

/*
 * Action 4$
 *
 * You may play an Action card from your hand twice. Trash it. Gain an Action card costing exactly 1 Coin more than it.
 */

class Procession extends Card implements iAction, iKingdom, iDarkAges {

    public function __construct() {
        parent::__construct("Procession", 4);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "You may play an Action card from your hand twice. Trash it. Gain an Action card costing exactly 1 Coin more than it.");
    }

    public function play(Game $game, $isRealCard) {
        $playHand = $game->getPlayHand();
        $action_cards = array();
        foreach ($playHand as $card) {
            if ($card instanceof iAction) {
                $action_cards[] = $card;
            }
        }

        if (sizeof($action_cards) > 0) {
            $action_cards = getUniqueCards($action_cards);
            if (sizeof($action_cards) > 1) {
                $output = MySocket::GetUserReply($game, Input_ChooseOne, $action_cards, 1, 1, null, "Choose an action card");
                $card_name = $output[0];
                $card = n2c($card_name);
            } else {
                $card = $action_cards[0];
            }

            $options = array(new Option(1, "Yes"), new Option(2, "No"));
            $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "Play " . $card->getValue() . " twice?");
            $answer = $output[0];
            if ($answer == "Yes") {

                ScreenDisplay::addScreenMessage($game, true, "play " . nicePrint($card) . " two times", " plays " . ScreenDisplay::$LMSG . " two times");

                $card = $game->moveCardFromPileToPile($card, PlayHand, PlayArea);

                $game->pushCardToStack($card, REAL_CARD);
                $game->pushCardToStack($card, VIRTUAL_CARD);

                $game->resolveCardsStack(2);
                $game->moveCardFromPileToPile($card, PlayArea, Trash);
            } else {
                $game->moveCardFromPileToPile($card, PlayHand, Trash);
                ScreenDisplay::addScreenMessage($game, true, "do not play " . nicePrint($card) . " two times", " does not play " . ScreenDisplay::$LMSG . " two times");
            }



            $price = $card->getPrice($game);
            $new_price = $price->add(1);
            $optional_cards = $game->getBoardActionCardsByPrice($new_price, $new_price);
            if (sizeof($optional_cards) > 0) {

                if (sizeof($optional_cards) > 1) {
                    $output = MySocket::GetUserReply($game, Input_ChooseOne, $optional_cards, 1, 1, null, "Choose action card to gain");
                    $card_name = $output[0];
                } else {
                    $card_name = $optional_cards[0];
                }

                $card = $game->moveCardFromPileToPile($card_name, BoardCards, DiscardPile);
                ScreenDisplay::addScreenMessage($game, false, " and gain " . nicePrint($card), " and gains " . ScreenDisplay::$LMSG);
            } else {
                ScreenDisplay::addScreenMessage($game, false, " and gain nothing", " and gains nothing ");
            }
        } else {
            ScreenDisplay::addScreenMessage($game, true, " play nothing", "plays nothing ");
        }
        $game->cardActionFinished();
        return true;
    }

}

?>